import com.google.gdata.client.spreadsheet.SpreadsheetService;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.ServiceException;

import java.net.URL;
import java.util.List;
import java.io.IOException;

/**
 * Date: Feb 28, 2007 Time: 4:56:50 PM
 *
 * @author pat
 */
// set lang level back to 5 for this. excluded.
public class TestG
{
    public static void main( String[] args ) throws IOException, ServiceException, InterruptedException
    {
        SpreadsheetService myService = new SpreadsheetService("exampleCo-exampleApp-1");
        myService.setUserCredentials("patniemeyer@gmail.com", "patsafe1");

        SpreadsheetFeed myFeed = myService.getFeed(
            new URL("http://spreadsheets.google.com/feeds/spreadsheets/private/full"),
            SpreadsheetFeed.class);

        List<SpreadsheetEntry> mySpreadsheetsList = myFeed.getEntries();
        System.out.println( "mySpreadsheetsList = " + mySpreadsheetsList );
        SpreadsheetEntry testSS = null;
        for ( int i = 0; i < mySpreadsheetsList.size(); i++ )
        {
            SpreadsheetEntry spreadsheetEntry = mySpreadsheetsList.get( i );
            if ( spreadsheetEntry.getTitle().getPlainText().equals("TestSpreadsheet") )
                testSS = spreadsheetEntry;
        }
        System.out.println( "testSS = " + testSS.getTitle().getPlainText() );

        List<WorksheetEntry> wsList = testSS.getWorksheets();
        System.out.println( "wsList = " + wsList );
        WorksheetEntry sheet1 = null;
        for (WorksheetEntry myWorksheet : wsList ) {
            System.out.println( "myWorksheet = " + myWorksheet.getTitle().getPlainText() );
            if ( myWorksheet.getTitle().getPlainText().equals("Sheet1") ) {
              sheet1 = myWorksheet;
            }
        }
        System.out.println( "sheet1 = " + sheet1 );

        //CellEntry newCell = new CellEntry(6, 1, "42");
        //myService.insert(sheet1.getCellFeedUrl(), newCell);

        ListEntry myEntry = new ListEntry();
        myEntry.getCustomElements().setValueLocal("HeaderOne", "1");
        myEntry.getCustomElements().setValueLocal("HeaderTwo", "2");
        myEntry.getCustomElements().setValueLocal("HeaderThree", "3");
        myService.insert(sheet1.getListFeedUrl(), myEntry);

        Thread.sleep(30*1000);
    }
    //new URL("http://localhost:8080/servlets-examples/servlet/RequestHeaderExample"),
}
